package com.servlet.meeting;

import com.domain.MeetingRecord;
import com.fasterxml.jackson.databind.util.BeanUtil;
import com.service.MeetingService;
import com.service.impl.MettingServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet( "/meetingUpdateServlet")
public class MeetingUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        MeetingRecord meetingRecord = new MeetingRecord();
        Map<String, String[]> me = request.getParameterMap();
        MeetingService upservice = new MettingServiceImpl();
        try {
            BeanUtils.populate(meetingRecord,me);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        request.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        if(upservice.update(meetingRecord)){
            response.getWriter().write("{\"status\":\"0\",\"massage\":\"ok\"}");
        }else{
            response.getWriter().write("{\"status\":\"1\",\"massage\":\"no\"}");
        }
    }
}
